<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
            label-width="68px">
            <el-form-item label="服务名称" prop="serveName">
                <el-input v-model="queryParams.serveName" placeholder="请输入服务名称" clearable style="width: 240px"
                    @keyup.enter.native="handleQuery" />
            </el-form-item>

            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>
        <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
                    v-hasPermi="['serveType:serveType:add']">新增</el-button>
            </el-col>
            <right-toolbar :showSearch.sync="showSearch" @queryTable="getserveTypeList"></right-toolbar>
        </el-row>
        <el-table v-loading="loading" :data="serveTypeList">
            <el-table-column label="服务名称" align="center" prop="serveName" />
            <el-table-column label="服务介绍" align="center" prop="serveInt"></el-table-column>
            <el-table-column label="创建人" align="center" prop="createBy" />
            <el-table-column label="创建时间" align="center" prop="createTime" width="180">
                <template slot-scope="scope">
                    <span>{{ parseTime(scope.row.createTime) }}</span>
                </template>
            </el-table-column>
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                <template slot-scope="scope">
                    <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
                        v-hasPermi="['serveType:serveType:edit']">修改</el-button>
                    <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
                        v-hasPermi="['serveType:serveType:remove']">删除</el-button>
                </template>
            </el-table-column>
        </el-table>

        <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
            @pagination="getserveTypeList" />


        <el-dialog title="提示" :visible.sync="dialogVisible" width="600px" append-to-body>
            <el-form ref="form" :model="form" label-width="80px">
                <el-form-item label="服务名称" prop="serveName">
                    <el-input v-model="form.serveName" placeholder="请输入服务名称" />
                </el-form-item>
                <el-form-item label="服务介绍">
                    <el-input v-model="form.serveInt" placeholder="请输入服务介绍" />
                </el-form-item>
                <el-form-item label="创建人">
                    <el-input v-model="form.createBy" placeholder="请输入创建人" />
                </el-form-item>
                <el-form-item label="备注" prop="remark">
                    <el-input v-model="form.remark" type="textarea" placeholder="请输入内容"></el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="SubmitForm">确 定</el-button>
                <el-button @click="dialogVisible= false">取 消</el-button>
              </div>
        </el-dialog>

    </div>
</template>

<script>
    import { selectServeTypeList ,addServeType,updateServeType,deleteServeType} from "@/api/servetype/serveType"
    export default {
        name: "ServeType",
        data() {
            return {
                //搜索条件
                showSearch: true,
                //遮罩层
                loading: true,
                // 总条数
                total: 0,
                // 查询参数
                queryParams: {
                    pageNum: 1,
                    pageSize: 10,
                    serveName: undefined,
                    serveInt: undefined,
                    createBy: undefined
                },
                dialogVisible: false,
                serveTypeList: [],
                // 表单参数
                form: {
                    serveName: undefined,
                    serveInt: undefined,
                    createBy: undefined,
                    remark: undefined,
                },
                // 表单校验
                rules: {

                }
            };
        },
        created() {
            this.getserveTypeList();
        },
        methods: {
            //搜索按钮
            handleQuery() {
                this.queryParams.pageNum = 1;
                this.getserveTypeList();
            },
            /** 重置按钮操作 */
            resetQuery() {
                this.queryParams = {
                    pageNum: 1,
                    pageSize: 10,
                    serveName: undefined,
                    serveInt: undefined,
                    createBy: undefined,
                };
                this.resetForm("queryForm");
                this.handleQuery();
            },
            //查询学生信息
            getserveTypeList() {
                selectServeTypeList(this.queryParams).then(response => {
                    this.serveTypeList = response.rows;
                    this.total = response.total;
                    this.loading = false;
                })
            },
            //新增按钮
            handleAdd() {
                this.reset();
                this.dialogVisible = true;
            },
            /** 修改按钮操作 */
            handleUpdate(row) {
                this.reset();
                this.dialogVisible = true;
                this.form = row;
            },
            // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },



            //提交按钮
            SubmitForm: function () {
                if (this.form.id != undefined) {
                    updateServeType(this.form).then(response => {
                        this.$modal.msgSuccess("修改成功");
                        this.dialogVisible = false;
                        this.getserveTypeList();
                    })
                } else {
                    addServeType(this.form).then(response => {
                        this.$modal.msgSuccess("新增成功");
                        this.dialogVisible = false;
                        this.getserveTypeList();
                    })
                }
            },
            /** 删除按钮操作 */
            handleDelete(row) {
                const id = row.id
                this.$modal.confirm('是否确认删除服务编号为"' + id + '"的数据项？').then(function () {
                    return deleteServeType(id);
                }).then(() => {
                    this.getserveTypeList();
                    this.$modal.msgSuccess("删除成功");
                }).catch(() => { });
            },


            //表单重置
            reset() {
                this.form = {
                    serveName: undefined,
                    serveInt: undefined,
                    createBy: undefined,
                };
                this.resetForm("form");
            },

        },
    };

</script>

<style>

</style>
